$OpenBSD: patch-res_res_fax_c,v 1.5 2015/06/08 08:44:52 sthen Exp $

https://issues.asterisk.org/jira/secure/attachment/46850/fax-deadlock-v2.patch-11.3.0

--- res/res_fax.c.orig	Thu Jun  4 01:44:42 2015
+++ res/res_fax.c	Fri Jun  5 10:41:19 2015
@@ -3398,10 +3398,13 @@ static struct ast_frame *fax_detect_framehook(struct a
 		switch (result) {
 		case 'f':
 		case 't':
+			if (!strcmp(ast_channel_exten(chan), "fax")) {
+				ast_debug(1, "Already in a fax extension, not redirecting\n");
+				break;
+			}
 			ast_channel_unlock(chan);
 			if (ast_exists_extension(chan, target_context, "fax", 1,
 			    S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL))) {
-				ast_channel_lock(chan);
 				ast_verb(2, "Redirecting '%s' to fax extension due to %s detection\n",
 					ast_channel_name(chan), (result == 'f') ? "CNG" : "T38");
 				pbx_builtin_setvar_helper(chan, "FAXEXTEN", ast_channel_exten(chan));
@@ -3411,10 +3414,10 @@ static struct ast_frame *fax_detect_framehook(struct a
 				ast_frfree(f);
 				f = &ast_null_frame;
 			} else {
-				ast_channel_lock(chan);
 				ast_log(LOG_NOTICE, "FAX %s detected but no fax extension in context (%s)\n",
 					(result == 'f') ? "CNG" : "T38", target_context);
 			}
+			ast_channel_lock(chan);
 		}
 		ast_framehook_detach(chan, details->faxdetect_id);
 		details->faxdetect_id = -1;
